package ru.myrtle.umf.impl;

import java.util.*;
import ru.myrtle.umf.*;
import ru.myrtle.umf.util.*;

public class UPackageImpl extends UObjectImpl implements UPackage {

    protected static final String NAMESPACE_PREFIX_DEFAULT = null;
    protected static final String NAMESPACE_URI_DEFAULT = null;
    protected static final String NAME_DEFAULT = null;
    protected static final String DESCRIPTION_DEFAULT = null;

    public UPackageImpl() {
    }

    @Override
    public UClass uClass() {
        return UModel.UPACKAGE;
    }
    
    private String _namespacePrefix_ = NAMESPACE_PREFIX_DEFAULT;

    @Override
    public final String getNamespacePrefix() {
        return _namespacePrefix_;
    }

    @Override
    public final boolean isSetNamespacePrefix() {
        return _namespacePrefix_ != NAMESPACE_PREFIX_DEFAULT;
    }

    @Override
    public final void setNamespacePrefix(String _namespacePrefix_) {
        this._namespacePrefix_ = _namespacePrefix_;
    }

    @Override
    public final void unsetNamespacePrefix() {
        _namespacePrefix_ = NAMESPACE_PREFIX_DEFAULT;
    }

    private String _namespaceURI_ = NAMESPACE_URI_DEFAULT;

    @Override
    public final String getNamespaceURI() {
        return _namespaceURI_;
    }

    @Override
    public final boolean isSetNamespaceURI() {
        return _namespaceURI_ != NAMESPACE_URI_DEFAULT;
    }

    @Override
    public final void setNamespaceURI(String _namespaceURI_) {
        this._namespaceURI_ = _namespaceURI_;
    }

    @Override
    public final void unsetNamespaceURI() {
        _namespaceURI_ = NAMESPACE_URI_DEFAULT;
    }

    private UList<UClassifier> _classifiers_;

    @Override
    public final UList<UClassifier> getClassifiers() {
        if (_classifiers_ == null) {
            _classifiers_ = new UObjectContainmentWithInverseList<UClassifier>(this, UModel.UPACKAGE__CLASSIFIERS, UModel.UCLASSIFIER__PACKAGE);
        }
        return _classifiers_;
    }

    @Override
    public final boolean isSetClassifiers() {
        return _classifiers_ != null && !_classifiers_.isEmpty();
    }

    @Override
    public void setClassifiers(UList<UClassifier> _classifiers_) {
        getClassifiers().clear();
        getClassifiers().addAll(_classifiers_);
    }

    @Override
    public void unsetClassifiers() {
        if (_classifiers_ != null) {
            _classifiers_.clear();
        }
    }

    @Override
    public final UList<UClass> getClasses() {
        return UPackageOperations.INSTANCE.getClasses(this);
    }

    @Override
    public final boolean isSetClasses() {
        return UPackageOperations.INSTANCE.isSetClasses(this);
    }

    @Override
    public final UList<UDataType> getDataTypes() {
        return UPackageOperations.INSTANCE.getDataTypes(this);
    }

    @Override
    public final boolean isSetDataTypes() {
        return UPackageOperations.INSTANCE.isSetDataTypes(this);
    }

    @Override
    public final UList<UEnumeration> getEnumerations() {
        return UPackageOperations.INSTANCE.getEnumerations(this);
    }

    @Override
    public final boolean isSetEnumerations() {
        return UPackageOperations.INSTANCE.isSetEnumerations(this);
    }

    private UPackage _superPackage_;

    @Override
    public final UPackage getSuperPackage() {
        return _superPackage_;
    }

    @Override
    public final boolean isSetSuperPackage() {
        return _superPackage_ != null;
    }

    private void setSuperPackageImpl(UPackage _superPackage_) {
        this._superPackage_ = _superPackage_;
    }

    private UList<UPackage> _subPackages_;

    @Override
    public final UList<UPackage> getSubPackages() {
        if (_subPackages_ == null) {
            _subPackages_ = new UObjectContainmentList<UPackage>(this, UModel.UPACKAGE__SUB_PACKAGES);
        }
        return _subPackages_;
    }

    @Override
    public final boolean isSetSubPackages() {
        return _subPackages_ != null && !_subPackages_.isEmpty();
    }

    @Override
    public void setSubPackages(UList<UPackage> _subPackages_) {
        getSubPackages().clear();
        getSubPackages().addAll(_subPackages_);
    }

    @Override
    public void unsetSubPackages() {
        if (_subPackages_ != null) {
            _subPackages_.clear();
        }
    }

    private UFactory _factory_;

    @Override
    public final UFactory getFactory() {
        return _factory_;
    }

    @Override
    public final boolean isSetFactory() {
        return _factory_ != null;
    }

    private void setFactoryImpl(UFactory _factory_) {
        this._factory_ = _factory_;
    }

    @Override
    public final void setFactory(UFactory _factory_) {
        if (this._factory_ != _factory_) {
            if (this._factory_ != null) {                this._factory_.uInternalDetach();                            }            setFactoryImpl(_factory_);
            if (this._factory_ != null) {                this._factory_.uInternalAttach(this, UModel.UPACKAGE__FACTORY);                            }        }
    }
    
    @Override
    public final void unsetFactory() {
        setFactoryImpl(null);
    }

    private String _name_ = NAME_DEFAULT;

    @Override
    public final String getName() {
        return _name_;
    }

    @Override
    public final boolean isSetName() {
        return _name_ != NAME_DEFAULT;
    }

    @Override
    public final void setName(String _name_) {
        this._name_ = _name_;
    }

    @Override
    public final void unsetName() {
        _name_ = NAME_DEFAULT;
    }

    private String _description_ = DESCRIPTION_DEFAULT;

    @Override
    public final String getDescription() {
        return _description_;
    }

    @Override
    public final boolean isSetDescription() {
        return _description_ != DESCRIPTION_DEFAULT;
    }

    @Override
    public final void setDescription(String _description_) {
        this._description_ = _description_;
    }

    @Override
    public final void unsetDescription() {
        _description_ = DESCRIPTION_DEFAULT;
    }

    private UList<UAnnotation> _annotations_;

    @Override
    public final UList<UAnnotation> getAnnotations() {
        if (_annotations_ == null) {
            _annotations_ = new UObjectContainmentList<UAnnotation>(this, UModel.UELEMENT__ANNOTATIONS);
        }
        return _annotations_;
    }

    @Override
    public final boolean isSetAnnotations() {
        return _annotations_ != null && !_annotations_.isEmpty();
    }

    @Override
    public void setAnnotations(UList<UAnnotation> _annotations_) {
        getAnnotations().clear();
        getAnnotations().addAll(_annotations_);
    }

    @Override
    public void unsetAnnotations() {
        if (_annotations_ != null) {
            _annotations_.clear();
        }
    }


    @Override
    @SuppressWarnings(
        "unchecked"
    )
    public Object uGet(UFeature feature) {
        if (feature == UModel.UPACKAGE__NAMESPACE_PREFIX) {
            return getNamespacePrefix();
        }
        if (feature == UModel.UPACKAGE__NAMESPACE_URI) {
            return getNamespaceURI();
        }
        if (feature == UModel.UPACKAGE__CLASSIFIERS) {
            return getClassifiers();
        }
        if (feature == UModel.UPACKAGE__CLASSES) {
            return getClasses();
        }
        if (feature == UModel.UPACKAGE__DATA_TYPES) {
            return getDataTypes();
        }
        if (feature == UModel.UPACKAGE__ENUMERATIONS) {
            return getEnumerations();
        }
        if (feature == UModel.UPACKAGE__SUPER_PACKAGE) {
            return getSuperPackage();
        }
        if (feature == UModel.UPACKAGE__SUB_PACKAGES) {
            return getSubPackages();
        }
        if (feature == UModel.UPACKAGE__FACTORY) {
            return getFactory();
        }
        if (feature == UModel.UELEMENT__NAME) {
            return getName();
        }
        if (feature == UModel.UELEMENT__DESCRIPTION) {
            return getDescription();
        }
        if (feature == UModel.UELEMENT__ANNOTATIONS) {
            return getAnnotations();
        }

        return super.uGet(feature);
    }

    @Override
    @SuppressWarnings(
        "unchecked"
    )
    public boolean uIsSet(UFeature feature) {
        if (feature == UModel.UPACKAGE__NAMESPACE_PREFIX) {
            return isSetNamespacePrefix();
        }
        if (feature == UModel.UPACKAGE__NAMESPACE_URI) {
            return isSetNamespaceURI();
        }
        if (feature == UModel.UPACKAGE__CLASSIFIERS) {
            return isSetClassifiers();
        }
        if (feature == UModel.UPACKAGE__CLASSES) {
            return isSetClasses();
        }
        if (feature == UModel.UPACKAGE__DATA_TYPES) {
            return isSetDataTypes();
        }
        if (feature == UModel.UPACKAGE__ENUMERATIONS) {
            return isSetEnumerations();
        }
        if (feature == UModel.UPACKAGE__SUPER_PACKAGE) {
            return isSetSuperPackage();
        }
        if (feature == UModel.UPACKAGE__SUB_PACKAGES) {
            return isSetSubPackages();
        }
        if (feature == UModel.UPACKAGE__FACTORY) {
            return isSetFactory();
        }
        if (feature == UModel.UELEMENT__NAME) {
            return isSetName();
        }
        if (feature == UModel.UELEMENT__DESCRIPTION) {
            return isSetDescription();
        }
        if (feature == UModel.UELEMENT__ANNOTATIONS) {
            return isSetAnnotations();
        }

        return super.uIsSet(feature);
    }

    @Override
    @SuppressWarnings(
        "unchecked"
    )
    public void uSet(UFeature feature, Object value) {
        if (feature == UModel.UPACKAGE__NAMESPACE_PREFIX) {
            setNamespacePrefix((String) value);
            return;
        }
        if (feature == UModel.UPACKAGE__NAMESPACE_URI) {
            setNamespaceURI((String) value);
            return;
        }
        if (feature == UModel.UPACKAGE__CLASSIFIERS) {
            setClassifiers((UList<UClassifier>) value);
            return;
        }
        if (feature == UModel.UPACKAGE__SUB_PACKAGES) {
            setSubPackages((UList<UPackage>) value);
            return;
        }
        if (feature == UModel.UPACKAGE__FACTORY) {
            setFactory((UFactory) value);
            return;
        }
        if (feature == UModel.UELEMENT__NAME) {
            setName((String) value);
            return;
        }
        if (feature == UModel.UELEMENT__DESCRIPTION) {
            setDescription((String) value);
            return;
        }
        if (feature == UModel.UELEMENT__ANNOTATIONS) {
            setAnnotations((UList<UAnnotation>) value);
            return;
        }

        super.uSet(feature, value);
    }

    @Override
    @SuppressWarnings(
        "unchecked"
    )
    public void uUnset(UFeature feature) {
        if (feature == UModel.UPACKAGE__NAMESPACE_PREFIX) {
            unsetNamespacePrefix();
            return;
        }
        if (feature == UModel.UPACKAGE__NAMESPACE_URI) {
            unsetNamespaceURI();
            return;
        }
        if (feature == UModel.UPACKAGE__CLASSIFIERS) {
            unsetClassifiers();
            return;
        }
        if (feature == UModel.UPACKAGE__SUB_PACKAGES) {
            unsetSubPackages();
            return;
        }
        if (feature == UModel.UPACKAGE__FACTORY) {
            unsetFactory();
            return;
        }
        if (feature == UModel.UELEMENT__NAME) {
            unsetName();
            return;
        }
        if (feature == UModel.UELEMENT__DESCRIPTION) {
            unsetDescription();
            return;
        }
        if (feature == UModel.UELEMENT__ANNOTATIONS) {
            unsetAnnotations();
            return;
        }

        super.uUnset(feature);
    }


    @Override
    @SuppressWarnings(
        "unchecked"
    )
    public void uInternalInverseAdd(UObject otherEnd, UReference reference) {
        if (reference == UModel.UPACKAGE__CLASSIFIERS) {
            ((UObjectList<UClassifier>) getClassifiers()).basicAdd((UClassifier) otherEnd);
            return;
        }
        if (reference == UModel.UPACKAGE__SUPER_PACKAGE) {
            setSuperPackageImpl((UPackage) otherEnd);
            return;
        }
    }

    @Override
    @SuppressWarnings(
        "unchecked"
    )
    public void uInternalInverseRemove(UObject otherEnd, UReference reference) {
        if (reference == UModel.UPACKAGE__CLASSIFIERS) {
            ((UObjectList<UClassifier>) getClassifiers()).basicRemove((UClassifier) otherEnd);
            return;
        }
        if (reference == UModel.UPACKAGE__SUPER_PACKAGE) {
            setSuperPackageImpl(null);
            return;
        }
    }


    @Override
    public String toString() {
        StringBuffer result = new StringBuffer();

        result.append("UPackage");
        result.append(" (");
        result.append("namespacePrefix: ");
        result.append(_namespacePrefix_);
        result.append(", ");
        result.append("namespaceURI: ");
        result.append(_namespaceURI_);
        result.append(", ");
        result.append("name: ");
        result.append(_name_);
        result.append(", ");
        result.append("description: ");
        result.append(_description_);
        result.append(')');

        return result.toString();
    }
}




